import { getsysuserListAPI, getsysUserfindAPI, getPageTablefindAPI, getPageSelectListAPI } from "@/api";
import { defineStore } from "pinia";
import { ref } from 'vue'

const useBaseStore = defineStore('base', () => {
  const sysuserList = ref<any>([])
  const sysuserTabs = ref<any>([])

  const pageTabs = ref<any>([])
  const pageSelectList = ref<any>([])
  const total = ref<number>(0)


  const feachBaseDataAction = async (dataInfo?: any) => {
    const res1 = await getsysuserListAPI()
    sysuserList.value = res1

    const res2 = await getsysUserfindAPI(dataInfo)
    sysuserTabs.value = res2
  }

  const feachPageTablesAction = async (pageName: string, mainMenuName: string, checkName: string, pageForm?: any, limt: number = 10, offset: number = 0) => {
    const res = await getPageTablefindAPI(pageName, mainMenuName, checkName, pageForm)
    total.value = res.length
    pageTabs.value = res.splice(offset, limt)
  }

  const feachPageSelectListAction = async (pageName: string, mainMenuName: string, seleteText: string) => {
    const res = await getPageSelectListAPI(pageName, mainMenuName, seleteText)
    pageSelectList.value = res
  }

  return {
    sysuserList,
    sysuserTabs,
    pageTabs,
    pageSelectList,
    total,
    feachBaseDataAction,
    feachPageTablesAction,
    feachPageSelectListAction
  }
})

export default useBaseStore
